import ProTable, {ActionType} from '@ant-design/pro-table';
import { PageContainer } from '@ant-design/pro-layout';
import { Card } from 'antd';
import {bargainList } from "@/services/ant-design-pro/marketing";
import {useRef} from "react";



export default () => {
  const actionRef = useRef<ActionType>();

  const columns = [
    {
      dataIndex: 'us',
      title: '订单号',
      search: false,
      align: 'center',
    },
    {
      title: '订单金额',
      dataIndex: 'title',
      align: 'center',
      copyable: true,
      ellipsis: true,
      search: false,
      render: (_,record) => <span>{record.user.nickname}</span>
    },
    {
      title: '时间选择',
      dataIndex: 'time',
      valueType: 'radioButton',
      initialValue: '',
      hideInTable: true,
      colSize: '24',
      valueEnum: {
        '': '全部',
        today: '今天',
        yesterday: '昨天',
        week: '最近7天',
        thirty: '最近30天',
        month: '本月',
        year: '本年'
      }
    },
    {
      title: '创建时间',
      dataIndex: 'start',
      hideInTable: true,
      valueType: 'dateRange',
      initialValue: '',
      valueEnum: {
        start: '开始时间',
        stop: '结束时间'
      }
    },
    // {
    //   title: '搜索',
    //   hideInTable: false,
    //   dataIndex: 'select',
    //   valueType: 'select',
    //   initialValue: 'all',
    //   render: ()=>[
    //     {
    //       label: '全部',
    //       value: 'all'
    //     },
    //     {
    //       label: '订单号',
    //       value: '',
    //     },
    //     {
    //       label: 'UID',
    //       value: '',
    //     },
    //     {
    //       label: '用户名称',
    //       value: '',
    //     },
    //     {
    //       label: '用户电话',
    //       value: '',
    //     },
    //     {
    //       label: '商品名称(模糊)',
    //       value: 3,
    //     },
    //   ]
    // },
    {
      title: '发票类型',
      dataIndex: 'time',
      align: 'center',
      search: false,
    },
    {
      title: '发票抬头类型',
      dataIndex: 'text',
      search: false,
      align: 'center',
    },
    {
      title: '下单时间',
      dataIndex: 'bargain_price_min',
      search: false,
      align: 'center',
      render: (_,record) => <span>{record.storeBargain.min_price}</span>
    },
    {
      title: '当前价',
      dataIndex: 'bargain_price',
      search: false,
      align: 'center',
      render: (_,record) => <span>{record.storeBargain.price}</span>
    },
    {
      title: '开票状态',
      search: false,
      dataIndex: 'status',
      align: 'center',
      valueType: 'select',
      initialValue: '',
      valueEnum:{
        participating: '进行中',
        endOfActivitySuccess: '已成功',
        endOfActivityFail: '已失败'
      },
    },
    {
      title: '操作',
      valueType: 'option',
      fixed: 'right',
      align: 'center',
      width: 200,
      render(_,record){
        return(
          record.status == '' ? <div>

          </div> : <div>

          </div>
        )
      }
    },
  ];

  return (
    <PageContainer
      header={{
        breadcrumb: {},
      }}
    >
      <Card>
        <ProTable

          actionRef={actionRef}
          columns={columns}
          request={async (params={}) => {
            let {data,meta} =  await bargainList({...params})
            return{
              data,
              success:true,
              total:meta.pagination.total
            }
          }}
          editable={{
            type: 'multiple',
          }}
          rowKey="id"
          search={{
            labelWidth: 'auto',
            defaultCollapsed: false,
            collapseRender: false,
          }}
          scroll={{ x: 1300 }}
          form={{
            // 由于配置了 transform，提交的参与与定义的不同这里需要转化一下
            syncToUrl: (values, type) => {
              if (type === 'get') {
                return {
                  ...values,
                  created_at: [values.startTime, values.endTime],
                };
              }
              return values;
            },
          }}
          pagination={{
            pageSize: 5,
          }}
          dateFormatter="string"
        />
      </Card>

    </PageContainer>

  );
};
